home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / stdio / RCS / stdio.c,v < prev   
Encoding:
Text File  |  1991-12-13  |  59.2 KB  |  2,402 lines

  1. head     1.12;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.12.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.12
  10. date     91.12.12.13.43.34;  author shirriff;  state Exp;
  11. branches 1.12.1.1;
  12. next     1.11;
  13.  
  14. 1.11
  15. date     89.03.16.11.54.28;  author ouster;  state Exp;
  16. branches ;
  17. next     1.10;
  18.  
  19. 1.10
  20. date     88.12.15.09.50.57;  author ouster;  state Exp;
  21. branches ;
  22. next     1.9;
  23.  
  24. 1.9
  25. date     88.10.23.15.39.22;  author ouster;  state Exp;
  26. branches ;
  27. next     1.8;
  28.  
  29. 1.8
  30. date     88.10.01.10.17.12;  author ouster;  state Exp;
  31. branches ;
  32. next     1.7;
  33.  
  34. 1.7
  35. date     88.07.21.10.57.09;  author ouster;  state Exp;
  36. branches ;
  37. next     1.6;
  38.  
  39. 1.6
  40. date     88.07.21.09.35.31;  author ouster;  state Exp;
  41. branches ;
  42. next     1.5;
  43.  
  44. 1.5
  45. date     88.07.20.18.11.18;  author ouster;  state Exp;
  46. branches ;
  47. next     1.4;
  48.  
  49. 1.4
  50. date     88.06.13.09.59.55;  author ouster;  state Exp;
  51. branches ;
  52. next     1.3;
  53.  
  54. 1.3
  55. date     88.06.10.10.19.52;  author ouster;  state Exp;
  56. branches ;
  57. next     1.2;
  58.  
  59. 1.2
  60. date     88.06.06.17.46.50;  author ouster;  state Exp;
  61. branches ;
  62. next     1.1;
  63.  
  64. 1.1
  65. date     88.06.06.08.43.33;  author ouster;  state Exp;
  66. branches ;
  67. next     ;
  68.  
  69. 1.12.1.1
  70. date     91.12.12.22.44.40;  author kupfer;  state Exp;
  71. branches ;
  72. next     ;
  73.  
  74.  
  75. desc
  76. @@
  77.  
  78.  
  79. 1.12
  80. log
  81. @Support for different byte orders.  (Mike checking in for Ken.)
  82. @
  83. text
  84. @/* 
  85.  * stdio.c --
  86.  *
  87.  *    This file contains a program that exercises the stdio
  88.  *    library facilities.  Invoke it with no parameters;  it
  89.  *    will print messages on stderr for any problems it detects
  90.  *    with the stdio procedures.
  91.  *
  92.  * Copyright 1988 Regents of the University of California
  93.  * Permission to use, copy, modify, and distribute this
  94.  * software and its documentation for any purpose and without
  95.  * fee is hereby granted, provided that the above copyright
  96.  * notice appear in all copies.  The University of California
  97.  * makes no representations about the suitability of this
  98.  * software for any purpose.  It is provided "as is" without
  99.  * express or implied warranty.
  100.  */
  101.  
  102. #ifndef lint
  103. static char rcsid[] = "$Header: /sprite/src/tests/stdio/RCS/stdio.c,v 1.11 89/03/16 11:54:28 ouster Exp $ SPRITE (Berkeley)";
  104. #endif not lint
  105.  
  106. #include <stdio.h>
  107. #include <string.h>
  108. #include <sys/file.h>
  109. #include <sys/wait.h>
  110. #include <signal.h>
  111. #include <varargs.h>
  112.  
  113. #ifdef sun3
  114. #define BIGENDIAN
  115. #endif
  116. #ifdef sun4
  117. #define BIGENDIAN
  118. #endif
  119. #ifdef ds3100
  120. #define LITTLEENDIAN
  121. #endif
  122.  
  123. #if 1
  124. #define error(string) \
  125.     fprintf(stderr, string); \
  126.     exit(1);
  127. #else
  128. #define error(string) \
  129.     fprintf(stderr, string);
  130. #endif
  131.  
  132. /*
  133.  *----------------------------------------------------------------------
  134.  *
  135.  * CheckFile --
  136.  *
  137.  *    Utility procedure to make sure that a given file contains a
  138.  *    given value.  Aborts with error if it doesn't.
  139.  *
  140.  * Results:
  141.  *    None.
  142.  *
  143.  * Side effects:
  144.  *    None.
  145.  *
  146.  *----------------------------------------------------------------------
  147.  */
  148.  
  149. void
  150. CheckFile(name, value, errMsg)
  151.     char *name;            /* Name of file to read. */
  152.     char *value;        /* Should match contents of file. */
  153.     char *errMsg;        /* Error message if there's a mismatch. */
  154. {
  155.     char buf[BUFSIZ];
  156.     int count, id;
  157.  
  158.     id = open(name, O_RDONLY, 0);
  159.     if (id < 0) {
  160.     error(errMsg);
  161.     }
  162.     count = read(id, buf, 1000);
  163.     if ((count == -1) || (count == 1000)) {
  164.     error(errMsg);
  165.     }
  166.     buf[count] = 0;
  167.     if (strcmp(buf, value) != 0) {
  168.     error(errMsg);
  169.     }
  170.     close(id);
  171. }
  172.  
  173. /*
  174.  *----------------------------------------------------------------------
  175.  *
  176.  * TsCheck --
  177.  *
  178.  *    Procedure for comparing two special-purpose structures, for
  179.  *    testing fread and fwrite.
  180.  *
  181.  * Results:
  182.  *    None.
  183.  *
  184.  * Side effects:
  185.  *    Aborts if ts1 and ts2 aren't equal.
  186.  *
  187.  *----------------------------------------------------------------------
  188.  */
  189.  
  190. typedef struct {
  191.     int x;
  192.     char c[6];
  193.     short y;
  194. } testStruct;
  195.  
  196. void
  197. TsCheck(ts1, ts2, msg)
  198.     testStruct *ts1, *ts2;        /* Two structures to compare for
  199.                      * equality. */
  200.     char *msg;                /* Message to print if mismatch. */
  201. {
  202.     int i;
  203.     if ((ts1->x != ts2->x) || (ts1->y != ts2->y)) {
  204.     error(msg);
  205.     }
  206.     for (i = 0; i < 6; i++) {
  207.     if (ts1->c[i] != ts2->c[i]) {
  208.         error(msg);
  209.     }
  210.     }
  211. }
  212.  
  213. /*
  214.  *----------------------------------------------------------------------
  215.  *
  216.  * CheckNext --
  217.  *
  218.  *    Procedure for testing fprintf:  reads back from a file and
  219.  *    makes sure what was printed had the right length and content..
  220.  *
  221.  * Results:
  222.  *    None.
  223.  *
  224.  * Side effects:
  225.  *    Aborts if the contents of the file's next line don't match string
  226.  *    and length.
  227.  *
  228.  *----------------------------------------------------------------------
  229.  */
  230.  
  231. void
  232. CheckNext(f, string, length, msg)
  233.     FILE *f;            /* File from which to read a line. */
  234.     char *string;        /* This should match exactly the line. */
  235.     int length;            /* The line should be this long. */
  236.     char *msg;            /* Error message to print if there's
  237.                  * a problem. */
  238. {
  239.     char buffer[500];
  240.     if (fgets(buffer, 500, f) == NULL) {
  241.     error(msg);
  242.     }
  243.     if (strlen(buffer) != length) {
  244.     error(msg);
  245.     }
  246.     if (strcmp(buffer, string) != 0) {
  247.     error(msg);
  248.     }
  249. }
  250.  
  251. /*
  252.  *----------------------------------------------------------------------
  253.  *
  254.  * CheckFp --
  255.  *
  256.  *    This procedure is used to check floating-point scanning.  It
  257.  *    prints the numbers, so as to do an approximate check, rather than
  258.  *    an exact one (fp conversion isn't exact, after all)..
  259.  *
  260.  * Results:
  261.  *    None.
  262.  *
  263.  * Side effects:
  264.  *    Aborts if the printed version of f1-f4 don't match string.
  265.  *
  266.  *----------------------------------------------------------------------
  267.  */
  268.  
  269. void
  270. CheckFp(count1, count2, f1, f2, f3, f4, string, msg)
  271.     int count1, count2;        /* These two counts better match. */
  272.     double f1, f2, f3, f4;    /* Four numbers; when printed in %e format,
  273.                  * they better match string. */
  274.     char *string;        /* Desired values of numbers. */
  275.     char *msg;            /* Error message. */
  276. {
  277.     char printed[200];
  278.  
  279.     if (count1 != count2) {
  280.     error(msg);
  281.     }
  282.     sprintf(printed, "%e %e %e %e", f1, f2, f3, f4);
  283.     if (strcmp(printed, string) != 0) {
  284.     printf("CheckFP: %s vs. %s\n", printed, string);
  285.     error(msg);
  286.     }
  287. }
  288.  
  289. /*
  290.  *----------------------------------------------------------------------
  291.  *
  292.  * CheckString --
  293.  *
  294.  *    Utility procedure for checking sscanf on strings.  Scans input
  295.  *    according to format, into four result strings, and compares them
  296.  *    against s1-s4.
  297.  *
  298.  * Results:
  299.  *    None.
  300.  *
  301.  * Side effects:
  302.  *    Aborts if there's a mismatch.
  303.  *
  304.  *----------------------------------------------------------------------
  305.  */
  306.  
  307.  
  308. void
  309. CheckString(input, format, count, s1, s2, s3, s4, msg)
  310.     char *format;        /* Format to use for scanning. */
  311.     char *input;        /* Input string to scan. */
  312.     int count;            /* Expected return value from sscanf. */
  313.     char *s1, *s2, *s3, *s4;    /* Scanned strings should match this. */
  314.     char *msg;            /* Message to print on error. */
  315. {
  316.     char c1[100], c2[100], c3[100], c4[100];
  317.     int result, i;
  318.  
  319.     for (i = 0; i < 100; i++) {
  320.     char c;
  321.     if (i < 5) {
  322.         c = 'X';
  323.     } else {
  324.         c = 0;
  325.     }
  326.     c1[i] = c2[i] = c3[i] = c4[i] = c;
  327.     }
  328.     result = sscanf(input, format, c1, c2, c3, c4);
  329.     if ((result != count) || (strcmp(c1, s1) != 0) || (strcmp(c2, s2) != 0)
  330.         || (strcmp(c3, s3) != 0) || (strcmp(c4, s4) != 0)) {
  331.     error(msg);
  332.     }
  333. }
  334.  
  335. /*
  336.  *----------------------------------------------------------------------
  337.  *
  338.  * CheckVprintf --
  339.  *
  340.  *    This procedure is used to check vprintf:  it just packages its
  341.  *    arguments and calls vprintf.
  342.  *
  343.  * Results:
  344.  *    Whatever vprintf returns.
  345.  *
  346.  * Side effects:
  347.  *    None.
  348.  *
  349.  *----------------------------------------------------------------------
  350.  */
  351.  
  352. int
  353. CheckVprintf(va_alist)
  354.     va_dcl        /* Format string followed by one or more arguments
  355.              * to printf. */
  356. {
  357.     char *format;
  358.     va_list args;
  359.  
  360.     va_start(args);
  361.     format = va_arg(args, char *);
  362.     return vprintf(format, args);
  363. }
  364.  
  365. /*
  366.  *----------------------------------------------------------------------
  367.  *
  368.  * CheckVsprintf --
  369.  *
  370.  *    This procedure is used to check vsprintf:  it just packages its
  371.  *    arguments and calls vsprintf.
  372.  *
  373.  * Results:
  374.  *    Whatever vsprintf returns.
  375.  *
  376.  * Side effects:
  377.  *    None.
  378.  *
  379.  *----------------------------------------------------------------------
  380.  */
  381.  
  382. char *
  383. CheckVsprintf(va_alist)
  384.     va_dcl        /* Format string followed by one or more arguments
  385.              * to printf. */
  386. {
  387.     char *string;
  388.     char *format;
  389.     va_list args;
  390.  
  391.     va_start(args);
  392.     string = va_arg(args, char *);
  393.     format = va_arg(args, char *);
  394.     return vsprintf(string, format, args);
  395. }
  396.  
  397. /*
  398.  *----------------------------------------------------------------------
  399.  *
  400.  * main --
  401.  *
  402.  *    Main program for stdio testing.
  403.  *
  404.  * Results:
  405.  *    None.
  406.  *
  407.  * Side effects:
  408.  *    Runs a whole bunch of little tests on the stdio procedures,
  409.  *    and aborts with an error message if any unexpected behavior
  410.  *    is observed.  Exits with 0 status and no output if all goes
  411.  *    well.
  412.  *
  413.  *----------------------------------------------------------------------
  414.  */
  415.  
  416. main()
  417. {
  418.     FILE *f1, *f2, *f3;
  419.     char buf[BUFSIZ], c;
  420.     int i, fd, fd2, pid, length, count;
  421.     testStruct tsArray1[20], tsArray2[20]; 
  422.     union wait status;
  423.     int d1, d2, d3, d4;
  424.     float fp1, fp2, fp3, fp4;
  425.     double dbl1, dbl2, dbl3, dbl4;
  426.     short s1, s2, s3, sa1[4], sa2[4];
  427.  
  428.     /*
  429.      * putc, fputc, fputs
  430.      */
  431.  
  432.     f1 = fopen("test", "w");
  433.     if (f1 == NULL) {
  434.     error("putc error 1\n");
  435.     }
  436.     if (putc('a', f1) == EOF) {
  437.     error("putc error 2\n");
  438.     }
  439.     if (putc('b', f1) == EOF) {
  440.     error("putc error 3\n");
  441.     }
  442.     if (fputc('c', f1) != 'c') {
  443.     error("putc error 4\n");
  444.     }
  445.     if (fputc('\n', f1) != '\n') {
  446.     error("putc error 5\n");
  447.     }
  448.     if (fputs("This is the second line.\n", f1) == EOF) {
  449.     error("putc error 6\n");
  450.     }
  451.     i = fclose(f1);
  452.     if (i != 0) {
  453.     error("putc error 7\n");
  454.     }
  455.     CheckFile("test", "abc\nThis is the second line.\n", "putc error 8\n");
  456.     f1 = fopen("test2", "w");
  457.     if (fputc(0377, f1) != 0377) {
  458.     error("putc error 9\n");
  459.     }
  460.     if (putc(0377, f1) != 0377) {
  461.     error("putc error 10\n");
  462.     }
  463.     if (fputc(-1, f1) != 0377) {
  464.     error("putc error 11\n");
  465.     }
  466.     if (putc(-1, f1) != 0377) {
  467.     error("putc error 12\n");
  468.     }
  469.     fclose(f1);
  470.     f1 = fopen("test", "r");
  471.     if (putc('a', f1) != EOF) {
  472.     error("putc error 13\n");
  473.     }
  474.     if (fputc('a', f1) != EOF) {
  475.     error("putc error 14\n");
  476.     }
  477.     if (fputs("abcde", f1) != EOF) {
  478.     error("putc error 15\n");
  479.     }
  480.  
  481.     /*
  482.      * getc, fgetc, fgets
  483.      */
  484.  
  485.     c = getc(f1);
  486.     if (c != 'a') {
  487.     error("getc error 1\n");
  488.     }
  489.     buf[4] = 'Z';
  490.     if (fgets(buf, 100, f1) == NULL) {
  491.     error("getc error 2\n");
  492.     }
  493.     if (strcmp(buf, "bc\n") != 0) {
  494.     error("getc error 3\n");
  495.     }
  496.     if (buf[4] != 'Z') {
  497.     error("getc error 4\n");
  498.     }
  499.     c = fgetc(f1);
  500.     if (c != 'T') {
  501.     error("getc error 5\n");
  502.     }
  503.     buf[10] = 'X';
  504.     if (fgets(buf, 10, f1) == NULL) {
  505.     error("getc error 6\n");
  506.     }
  507.     if (strcmp(buf, "his is th") != 0) {
  508.     error("getc error 7\n");
  509.     }
  510.     if (buf[10] != 'X') {
  511.     error("getc error 8\n");
  512.     }
  513.     buf[16] = 0377;
  514.     if (fgets(buf, 100, f1) == NULL) {
  515.     error("getc error 9\n");
  516.     }
  517.     if (strcmp(buf, "e second line.\n") != 0) {
  518.     error("getc error 8\n");
  519.     }
  520.     if (buf[16] != -1) {
  521.     error("getc error 9\n");
  522.     }
  523.     if (getc(f1) != EOF) {
  524.     error("getc error 10\n");
  525.     }
  526.     if (fgetc(f1) != EOF) {
  527.     error("getc error 11\n");
  528.     }
  529.     if (fgets(buf, 1000, f1) != NULL) {
  530.     error("getc error 12\n");
  531.     }
  532.     i = fclose(f1);
  533.     if (i != 0) {
  534.     error("getc error 13\n");
  535.     }
  536.     f1 = fopen("test", "w");
  537.     if (f1 == NULL) {
  538.     error("getc error 14\n");
  539.     }
  540.     if (getc(f1) != EOF) {
  541.     error("getc error 15\n");
  542.     }
  543.     fputs("Line with no return", f1);
  544.     fclose(f1);
  545.     f1 = fopen("test", "r");
  546.     if (f1 == NULL) {
  547.     error("getc error 16\n");
  548.     }
  549.     if (fgets(buf, 1000, f1) != NULL) {
  550.     error("getc error 17\n");
  551.     }
  552.     fclose(f1);
  553.  
  554.     /*
  555.      * putw, getw
  556.      */
  557.  
  558.     f1 = fopen("test", "w");
  559.     if (f1 == NULL) {
  560.     error("putw error 1\n");
  561.     }
  562.     putc('a', f1);
  563.     if (putw(0x010203ff, f1) != 0) {
  564.     error("putw error 2\n");
  565.     }
  566.     if (putw(0x04050607, f1) != 0) {
  567.     error("putw error 3\n");
  568.     }
  569.     if (getw(f1) != EOF) {
  570.     error("putw error 4\n");
  571.     }
  572.     fclose(f1);
  573. #ifndef LITTLEENDIAN
  574.     CheckFile("test", "a\1\2\3\377\4\5\6\7", "putw error 5(B)\n");
  575. #endif
  576. #ifndef BIGENDIAN
  577.     CheckFile("test", "a\377\3\2\1\7\6\5\4", "putw error 5(L)\n");
  578. #endif
  579.     f1 = fopen("test", "r");
  580.     if (f1 == NULL) {
  581.     error("putw error 6\n");
  582.     }
  583.     (void) getc(f1);
  584.     d1 = getw(f1);
  585.     if (feof(f1)) {
  586.     error("putw error 7\n");
  587.     }
  588.     d2 = getw(f1);
  589.     if (feof(f1)) {
  590.     error("putw error 8\n");
  591.     }
  592.     d3 = getw(f1);
  593.     if (!feof(f1)) {
  594.     error("putw error 9\n");
  595.     }
  596.     if ((d1 != 0x010203ff) || (d2 != 0x04050607) || (d3 != EOF)) {
  597.     error("putw error 10\n");
  598.     }
  599.     if (putw(1, f1) != EOF) {
  600.     error("putw error 11\n");
  601.     }
  602.     fclose(f1);
  603.  
  604.     /*
  605.      * fileno
  606.      */
  607.  
  608.     if (fileno(stdin) != 0) {
  609.     error("fileno error 1\n");
  610.     }
  611.     if (fileno(stdout) != 1) {
  612.     error("fileno error 2\n");
  613.     }
  614.     if (fileno(stderr) != 2) {
  615.     error("fileno error 3\n");
  616.     }
  617.     fd = dup(1);
  618.     fclose(stdout);
  619.     f1 = fopen("test", "w");
  620.     if (fileno(f1) != 1) {
  621.     error("fileno error 4\n");
  622.     }
  623.  
  624.     /*
  625.      * putchar, puts
  626.      */
  627.  
  628.     if (putchar('x') == EOF) {
  629.     error("putchar error 1\n");
  630.     }
  631.     if (puts(" more on this line.") == EOF) {
  632.     error("putchar error 2\n");
  633.     }
  634.     if (puts("A second line.") == EOF) {
  635.     error("putchar error 3\n");
  636.     }
  637.     fclose(f1);
  638.     if (putchar('x') != EOF) {
  639.     error("putchar error 4\n");
  640.     }
  641.     if (puts("More junk.") != EOF) {
  642.     error("putchar error 5\n");
  643.     }
  644.     dup2(fd, 1);
  645.     (void) fdopen(1, "w");
  646.     CheckFile("test", "x more on this line.\nA second line.\n",
  647.         "putchar error 6\n");
  648.     close(fd);
  649.  
  650.     /*
  651.      * getchar, gets
  652.      */
  653.  
  654.     fd = dup(0);
  655.     fclose(stdin);
  656.     f1 = fopen("test", "r");
  657.     if (fileno(f1) != 0) {
  658.     error("getchar error 1\n");
  659.     }
  660.     if (getchar() != 'x') {
  661.     error("getchar error 2\n");
  662.     }
  663.     if (getchar() != ' ') {
  664.     error("getchar error 3\n");
  665.     }
  666.     if (gets(buf) != buf) {
  667.     error("gets error 1\n");
  668.     }
  669.     if (strcmp(buf, "more on this line.") != 0) {
  670.     error("gets error 2\n");
  671.     }
  672.     if (gets(buf) != buf) {
  673.     error("gets error 3\n");
  674.     }
  675.     if (strcmp(buf, "A second line.") != 0) {
  676.     error("gets error 4\n");
  677.     }
  678.     if (gets(buf) != NULL) {
  679.     error("gets error 5\n");
  680.     }
  681.     if (getchar() != EOF) {
  682.     error("getchar error 4\n");
  683.     }
  684.     dup2(fd, 0);
  685.     (void) fdopen(0, "r");
  686.     close(fd);
  687.  
  688.     /*
  689.      * fwrite, fread
  690.      */
  691.  
  692.     for (i = 0; i < 10; i++) {
  693.     int j;
  694.  
  695.     tsArray1[i].x = 0x52ff6984 + i;
  696.     tsArray1[i].y = 47+i;
  697.     for (j = 0; j < 6; j++) {
  698.         tsArray1[i].c[j] = 'A' + 2*i + j;
  699.     }
  700.     }
  701.     f1 = fopen("test", "w");
  702.     f2 = fopen("test", "r");
  703.     if (f1 == NULL) {
  704.     error("fwrite error 1\n");
  705.     }
  706.     if (f2 == NULL) {
  707.     error("fread error 1\n");
  708.     }
  709.     if (fwrite(tsArray1, sizeof(testStruct), 10, f1) != 10) {
  710.     error("fwrite error 2\n");
  711.     }
  712.     if (fwrite(&tsArray1[3], sizeof(testStruct), 5, f1) != 5) {
  713.     error("fwrite error 3\n");
  714.     }
  715.     if (fwrite(tsArray1, sizeof(testStruct), 1, f1) != 1) {
  716.     error("fwrite error 4\n");
  717.     }
  718.     if (fwrite(tsArray1, sizeof(testStruct), 1, f2) != 0) {
  719.     error("fwrite error 5\n");
  720.     }
  721.     fclose(f1);
  722.     if (fread(tsArray2, sizeof(testStruct), 2, f2) != 2) {
  723.     error("fread error 2\n");
  724.     }
  725.     TsCheck(&tsArray1[0], &tsArray2[0], "fread error 3\n");
  726.     TsCheck(&tsArray1[1], &tsArray2[1], "fread error 4\n");
  727.     if (fread(tsArray2, sizeof(testStruct), 10, f2) != 10) {
  728.     error("fread error 5\n");
  729.     }
  730.     for (i = 0; i < 10; i++) {
  731.     if (i >= 8) {
  732.         TsCheck(&tsArray1[i-5], &tsArray2[i], "fread error 6\n");
  733.     } else {
  734.         TsCheck(&tsArray1[i+2], &tsArray2[i], "fread error 7\n");
  735.     }
  736.     }
  737.     if (fread(tsArray2, sizeof(testStruct), 1, f2) != 1) {
  738.     error("fread error 8\n");
  739.     }
  740.     TsCheck(&tsArray1[5], &tsArray2[0], "fread error 9\n");
  741.     if (fread(tsArray2, sizeof(testStruct), 5, f2) != 3) {
  742.     error("fread error 10\n");
  743.     }
  744.     TsCheck(&tsArray1[6], &tsArray2[0], "fread error 11\n");
  745.     TsCheck(&tsArray1[7], &tsArray2[1], "fread error 12\n");
  746.     TsCheck(&tsArray1[0], &tsArray2[2], "fread error 13\n");
  747.     if (fread(tsArray2, sizeof(testStruct), 1, f2) != 0) {
  748.     error("fread error 14\n");
  749.     }
  750.     fclose(f2);
  751.  
  752.     /*
  753.      * fseek, rewind, and ftell
  754.      */
  755.  
  756.     f1 = fopen("test", "w+");
  757.     if (f1 == NULL) {
  758.     error("fseek error 1\n");
  759.     }
  760.     fputs("abcdefghijklmnopqrstuvwxyz", f1);
  761.     if (ftell(f1) != 26) {
  762.     error("fseek error 2\n");
  763.     }
  764.     fseek(f1, 2, SEEK_SET);
  765.     putc('1', f1);
  766.     if (ftell(f1) != 3) {
  767.     error("fseek error 3\n");
  768.     }
  769.     fseek(f1, 4, SEEK_CUR);
  770.     putc('2', f1);
  771.     if (ftell(f1) != 8) {
  772.     error("fseek error 4\n");
  773.     }
  774.     fseek(f1, -1, SEEK_END);
  775.     fputs("345", f1);
  776.     if (ftell(f1) != 28) {
  777.     error("fseek error 5\n");
  778.     }
  779.     fflush(f1);
  780.     CheckFile("test", "ab1defg2ijklmnopqrstuvwxy345", "fseek error 6\n");
  781.     fseek(f1, 1, SEEK_SET);
  782.     if (getc(f1) != 'b') {
  783.     error("fseek error 7\n");
  784.     }
  785.     if (ftell(f1) != 2) {
  786.     error("fseek error 8\n");
  787.     }
  788.     fseek(f1, -2, SEEK_END);
  789.     if (ftell(f1) != 26) {
  790.     error("fseek error 9\n");
  791.     }
  792.     if (getc(f1) != '4') {
  793.     error("fseek error 10\n");
  794.     }
  795.     if (getc(f1) != '5') {
  796.     error("fseek error 11\n");
  797.     }
  798.     if (getc(f1) != EOF) {
  799.     error("fseek error 12\n");
  800.     }
  801.     if (fseek(f1, -1, SEEK_CUR) != 0) {
  802.     error("fseek error 13\n");
  803.     }
  804.     if (getc(f1) != '5') {
  805.     error("fseek error 14\n");
  806.     }
  807.     rewind(f1);
  808.     if (getc(f1) != 'a') {
  809.     error("fseek error 15\n");
  810.     }
  811.     fclose(f1);
  812.     /*
  813.      * Check fseeks across buffer boundaries and with both read-only
  814.      * streams and read-write streams.
  815.      */
  816.     f1 = fopen("test", "w");
  817.     if (f1 == NULL) {
  818.     error("fseek error 16\n");
  819.     }
  820.     for (i = 0; i <= 3 * BUFSIZ - 1; i++) {
  821.     putc(i&0xff, f1);
  822.     }
  823.     fclose(f1);
  824.     f1 = fopen("test", "r");
  825.     if (f1 == NULL) {
  826.     error("fseek error 16a\n");
  827.     }
  828.     if (getc(f1) != 0) {
  829.     error("fseek error 17\n");
  830.     }
  831.     fseek(f1, 0, SEEK_SET);
  832.     if (getc(f1) != 0) {
  833.     error("fseek error 17a\n");
  834.     }
  835.     fseek(f1, BUFSIZ-1, SEEK_SET);
  836.     if (getc(f1) != ((BUFSIZ-1) & 0xff)) {
  837.     error("fseek error 18\n");
  838.     }
  839.     fseek(f1, BUFSIZ+1, SEEK_SET);
  840.     if (getc(f1) != ((BUFSIZ+1) & 0xff)) {
  841.     error("fseek error 19\n");
  842.     }
  843.     if (getc(f1) != ((BUFSIZ+2) & 0xff)) {
  844.     error("fseek error 20\n");
  845.     }
  846.     fseek(f1, 3 * BUFSIZ - 2, SEEK_SET);
  847.     if (getc(f1) != ((3 * BUFSIZ - 2) & 0xff)) {
  848.     error("fseek error 21\n");
  849.     }
  850.     if (getc(f1) != ((3 * BUFSIZ - 1) & 0xff)) {
  851.     error("fseek error 22\n");
  852.     }
  853.     if (getc(f1) != EOF) {
  854.     error("fseek error 23\n");
  855.     }
  856.     fclose(f1);
  857.     f1 = fopen("test", "r+");
  858.     if (f1 == NULL) {
  859.     error("fseek error 24\n");
  860.     }
  861.     for (i = 0; i < 3 * BUFSIZ - 1; i++) {
  862.     putc(i&0xff, f1);
  863.     }
  864.     fseek(f1, 0, SEEK_SET);
  865.     if (getc(f1) != 0) {
  866.     error("fseek error 25\n");
  867.     }
  868.     fseek(f1, BUFSIZ-1, SEEK_SET);
  869.     if (getc(f1) != ((BUFSIZ-1) & 0xff)) {
  870.     error("fseek error 26\n");
  871.     }
  872.     fseek(f1, BUFSIZ+1, SEEK_SET);
  873.     if (getc(f1) != ((BUFSIZ+1) & 0xff)) {
  874.     error("fseek error 27\n");
  875.     }
  876.     if (getc(f1) != ((BUFSIZ+2) & 0xff)) {
  877.     error("fseek error 28\n");
  878.     }
  879.     fseek(f1, 3 * BUFSIZ - 2, SEEK_SET);
  880.     if (getc(f1) != ((3 * BUFSIZ - 2) & 0xff)) {
  881.     error("fseek error 29\n");
  882.     }
  883.     if (getc(f1) != ((3 * BUFSIZ - 1) & 0xff)) {
  884.     error("fseek error 30\n");
  885.     }
  886.     if (getc(f1) != EOF) {
  887.     error("fseek error 31\n");
  888.     }
  889.     fclose(f1);
  890.     
  891.     
  892.  
  893.     /*
  894.      * Buffering: setbuf, setbuffer, setlinebuf, setvbuf, fflush
  895.      */
  896.  
  897.     f1 = fopen("test", "w");
  898.     if (f1 == NULL) {
  899.     error("setvbuf error 1\n");
  900.     }
  901.     if (setvbuf(f1, buf, _IOFBF, 10) != 0) {
  902.     error("setvbuf error 2\n");
  903.     }
  904.     fputs("abcd\nefgh", f1);
  905.     if (strncmp(buf, "abcd\nefgh", 9) != 0) {
  906.     error("setvbuf error 3\n");
  907.     }
  908.     CheckFile("test", "", "setvbuf error 4\n");
  909.     putc('i', f1);
  910.     CheckFile("test", "abcd\nefghi", "setvbuf error 5\n");
  911.     fseek(f1, 0, SEEK_SET);
  912.     if (setvbuf(f1, 0, _IOLBF, 100) != 0) {
  913.     error("setvbuf error 6\n");
  914.     }
  915.     buf[0] = buf[1] = 0;
  916.     fputs("123456\n7890", f1);
  917.     if (buf[0] != 0) {
  918.     error("setvbuf error 7\n");
  919.     }
  920.     CheckFile("test", "123456\nghi", "setvbuf error 8\n");
  921.     if (fflush(f1) != 0) {
  922.     error("setvbuf error 9\n");
  923.     }
  924.     CheckFile("test", "123456\n7890", "setvbuf error 10\n");
  925.     putc('X', f1);
  926.     CheckFile("test", "123456\n7890", "setvbuf error 11\n");
  927.     if (setvbuf(f1, 0, _IONBF, BUFSIZ) != 0) {
  928.     error("setvbuf error 11\n");
  929.     }
  930.     CheckFile("test", "123456\n7890X", "setvbuf error 12\n");
  931.     putc('Y', f1);
  932.     CheckFile("test", "123456\n7890XY", "setvbuf error 13\n");
  933.     if (setvbuf(f1, 0, _IOFBF, 1) != 0) {
  934.     error("setvbuf error 14\n");
  935.     }
  936.     putc('Z', f1);
  937.     CheckFile("test", "123456\n7890XYZ", "setvbuf error 15\n");
  938.     setbuf(f1, buf);
  939.     for (i = 0; i < BUFSIZ-1; i++) {
  940.     putc(i&0xff, f1);
  941.     }
  942.     if ((buf[0] != 0) || ((buf[BUFSIZ-2] & 0xff) != ((BUFSIZ-2)&0xff))) {
  943.     error("setbuf error 1\n");
  944.     }
  945.     CheckFile("test", "123456\n7890XYZ", "setbuf error 2\n");
  946.     f2 = fopen("test", "r");
  947.     fseek(f2, 14, SEEK_SET);
  948.     if (getc(f2) != EOF) {
  949.     error("setbuf error 2\n");
  950.     }
  951.     putc('a', f1);
  952.     clearerr(f2);
  953.     c = getc(f2);
  954.     if (c != 0) {
  955.     error("setbuf error 3\n");
  956.     }
  957.     fseek(f2, BUFSIZ-3, SEEK_CUR);
  958.     c = getc(f2);
  959.     if ((c&0xff) != ((BUFSIZ-2)&0xff)) {
  960.     error("setbuf error 4\n");
  961.     }
  962.     if (getc(f2) != 'a') {
  963.     error("setbuf error 5\n");
  964.     }
  965.     if (getc(f2) != EOF) {
  966.     error("setbuf error 6\n");
  967.     }
  968.     fseek(f1, 0, SEEK_SET);
  969.     clearerr(f2);
  970.     fseek(f2, 0, SEEK_SET);
  971.     setlinebuf(f1);
  972.     putc('a', f1);
  973.     c = getc(f2);
  974.     if (c != '1') {
  975.     error("setlinebuf error 1\n");
  976.     }
  977.     putc('\n', f1);
  978.     f2 = freopen("test", "r", f2);
  979.     if (getc(f2) != 'a') {
  980.     error("setlinebuf error 2\n");
  981.     }
  982.     if (getc(f2) != '\n') {
  983.     error("setlinebuf error 3\n");
  984.     }
  985.     fclose(f2);
  986.     fclose(f1);
  987.     f1 = fopen("test", "w");
  988.     if (f1 == NULL) {
  989.     error("setbuffer error 1\n");
  990.     }
  991.     setbuffer(f1, buf, 5);
  992.     fputs("ABCD", f1);
  993.     if (strncmp(buf, "ABCD", 4) != 0) {
  994.     error("setbuffer error 2\n");
  995.     }
  996.     CheckFile("test", "", "setbuffer error 3\n");
  997.     putc('E', f1);
  998.     CheckFile("test", "ABCDE", "setbuffer error 4\n");
  999.     setbuffer(f1, 0, 1000);
  1000.     putc('F', f1);
  1001.     CheckFile("test", "ABCDEF", "setbuffer error 5\n");
  1002.     fclose(f1);
  1003.     fclose(f2);
  1004.  
  1005.     /*
  1006.      * ungetc
  1007.      */
  1008.  
  1009.     f1 = fopen("test", "r");
  1010.     (void) getc(f1);
  1011.     (void) getc(f1);
  1012.     if (ungetc('x', f1) != 'x') {
  1013.     error("ungetc error 1\n");
  1014.     }
  1015.     if (ungetc('y', f1) != 'y') {
  1016.     error("ungetc error 2\n");
  1017.     }
  1018.     if (ungetc('a', f1) != EOF) {
  1019.     error("ungetc error 3\n");
  1020.     }
  1021.     fgets(buf, 100, f1);
  1022.     if (getc(f1) != EOF) {
  1023.     error("ungetc error 4\n");
  1024.     }
  1025.     if (ungetc('#', f1) != '#') {
  1026.     error("ungetc error 5\n");
  1027.     }
  1028.     if (ungetc(EOF, f1) != EOF) {
  1029.     error("ungetc error 6\n");
  1030.     }
  1031.     if (getc(f1) != '#') {
  1032.     error("ungetc error 7\n");
  1033.     }
  1034.     if (getc(f1) != EOF) {
  1035.     error("ungetc error 8\n");
  1036.     }
  1037.  
  1038.     /*
  1039.      * fopen
  1040.      */
  1041.  
  1042.     f1 = fopen("test", "w");
  1043.     if (f1 == NULL) {
  1044.     error("fopen error 1\n");
  1045.     }
  1046.     CheckFile("test", "", "fopen error 2\n");
  1047.     fputs("Test output", f1);
  1048.     fseek(f1, 0, SEEK_SET);
  1049.     if (getc(f1) != EOF) {
  1050.     error("fopen error 3\n");
  1051.     }
  1052.     fclose(f1);
  1053.     f1 = fopen("test", "r");
  1054.     if (f1 == NULL) {
  1055.     error("fopen error 4\n");
  1056.     }
  1057.     if (getc(f1) != 'T') {
  1058.     error("fopen error 5\n");
  1059.     }
  1060.     if (putc('x', f1) != EOF) {
  1061.     error("fopen error 6\n");
  1062.     }
  1063.     fclose(f1);
  1064.     f1 = fopen("test", "a");
  1065.     if (f1 == NULL) {
  1066.     error("fopen error 7\n");
  1067.     }
  1068.     fputs(" continued", f1);
  1069.     fseek(f1, 0, SEEK_SET);
  1070.     fputs(" again", f1);
  1071.     fclose(f1);
  1072.     CheckFile("test", " againutput continued", "fopen error 8\n");
  1073.     f1= fopen("test", "w");
  1074.     fputs("Test output continued again", f1);
  1075.     fclose(f1);
  1076.     f1= fopen("test", "rb+");
  1077.     if (f1 == NULL) {
  1078.     error("fopen error 9\n");
  1079.     }
  1080.     if (getc(f1) != 'T') {
  1081.     error("fopen error 10\n");
  1082.     }
  1083.     fseek(f1, 0, SEEK_CUR);
  1084.     if (fputs("urd", f1) == EOF) {
  1085.     error("fopen error 11\n");
  1086.     }
  1087.     fclose(f1);
  1088.     CheckFile("test", "Turd output continued again", "fopen error 12\n");
  1089.     f1 = fopen("test", "w+");
  1090.     if (f1 == NULL) {
  1091.     error("fopen error 13\n");
  1092.     }
  1093.     CheckFile("test", "", "fopen error 14\n");
  1094.     if (fputs("Again", f1) == EOF) {
  1095.     error("fopen error 15\n");
  1096.     }
  1097.     fclose(f1);
  1098.     f1 = fopen("test", "a+b");
  1099.     if (f1 == NULL) {
  1100.     error("fopen error 16\n");
  1101.     }
  1102.     fputs(" written", f1);
  1103.     fflush(f1);
  1104.     CheckFile("test", "Again written", "fopen error 17\n");
  1105.     fseek(f1, 0, SEEK_SET);
  1106.     if (getc(f1) != 'A') {
  1107.     error("fopen error 18\n");
  1108.     }
  1109.     fseek(f1, 0, SEEK_CUR);
  1110.     fputs(" to\n", f1);
  1111.     fclose(f1);
  1112.     CheckFile("test", "A to\n written", "fopen error 19\n");
  1113.     f1 = fopen("test", "w");
  1114.     fputs("Again written to\n", f1);
  1115.     fclose(f1);
  1116.     if (fopen("test", "q") != NULL) {
  1117.     error("fopen error 20\n");
  1118.     }
  1119.     if (fopen("test", "ba") != NULL) {
  1120.     error("fopen error 21\n");
  1121.     }
  1122.  
  1123.     /*
  1124.      * fdopen, freopen
  1125.      */
  1126.  
  1127.     fd = open("test", O_RDONLY, 0666);
  1128.     if (fd == -1) {
  1129.     error("fdopen error 1\n");
  1130.     }
  1131.     f1 = fdopen(fd, "r");
  1132.     if (fgets(buf, 100, f1) == NULL) {
  1133.     error("fdopen error 2\n");
  1134.     }
  1135.     if (strcmp(buf, "Again written to\n") != 0) {
  1136.     error("fdopen error 3\n");
  1137.     }
  1138.     /*
  1139.      * Tricky stuff:  it must be possible to have two FILE's open
  1140.      * simultaneously on the same stream id.  Sounds crazy, but some
  1141.      * UNIX programs depend on it.
  1142.      */
  1143.     f2 = fopen("test2", "w");
  1144.     f3 = fdopen(fileno(f2), "w");
  1145.     if (fputs("Test1", f2) == NULL) {
  1146.     error("fdopen error 4\n");
  1147.     }
  1148.     if (fputs("Test2", f3) == NULL) {
  1149.     error("fdopen error 5\n");
  1150.     }
  1151.     if (fputs(" and test3", f2) == NULL) {
  1152.     error("fdopen error 6\n");
  1153.     }
  1154.     if (fputs(" and test4", f3) == NULL) {
  1155.     error("fdopen error 7\n");
  1156.     }
  1157.     fflush(f2);
  1158.     fflush(f3);
  1159.     CheckFile("test2", "Test1 and test3Test2 and test4", "fdopen error 8\n");
  1160.     fclose(f2);
  1161.     fclose(f3);
  1162.     /*
  1163.      * More tricky stuff:  fdopen must seek to the end of the file in
  1164.      * "a" mode:  some UNIX programs depend on it.
  1165.      */
  1166.     fd = open("test2", O_WRONLY, 0666);
  1167.     if (fd == -1) {
  1168.     error("fdopen error 9\n");
  1169.     }
  1170.     f2 = fdopen(fd, "a");
  1171.     fputs(" and more", f2);
  1172.     fclose(f2);
  1173.     CheckFile("test2", "Test1 and test3Test2 and test4 and more",
  1174.         "fdopen error 10\n");
  1175.  
  1176.     f1 = freopen("test2", "w", f1);
  1177.     if (f1 == NULL) {
  1178.     error("freopen error 1\n");
  1179.     }
  1180.     if (fputs("Output data\n", f1) == EOF) {
  1181.     error("freopen error 2\n");
  1182.     }
  1183.     f1 = freopen("test2", "r", f1);
  1184.     if (f1 == NULL) {
  1185.     error("freopen error 3\n");
  1186.     }
  1187.     if (fgets(buf, 100, f1) == NULL) {
  1188.     error("freopen error 4\n");
  1189.     }
  1190.     if (strcmp(buf, "Output data\n") != 0) {
  1191.     error("freopen error 5\n");
  1192.     }
  1193.     CheckFile("test2", "Output data\n", "freopen error 6\n");
  1194.     fclose(f1);
  1195.  
  1196.     /*
  1197.      * feof, ferror, clearerr
  1198.      */
  1199.  
  1200.     f1 = fopen("test", "r");
  1201.     f2 = fopen("test", "w");
  1202.     if ((f1 == NULL) || (f2 == NULL)) {
  1203.     error("ferror error 1\n");
  1204.     }
  1205.     if (getc(f1) != EOF) {
  1206.     error("ferror error 2\n");
  1207.     }
  1208.     if (!feof(f1)) {
  1209.     error("ferror error 3\n");
  1210.     }
  1211.     putc('a', f2);
  1212.     fclose(f2);
  1213.     if (getc(f1) != EOF) {
  1214.     error("ferror error 4\n");
  1215.     }
  1216.     if (!feof(f1)) {
  1217.     error("ferror error 5\n");
  1218.     }
  1219.     clearerr(f1);
  1220.     if (feof(f1)) {
  1221.     error("ferror error 6\n");
  1222.     }
  1223.     if (getc(f1) != 'a') {
  1224.     error("ferror error 7\n");
  1225.     }
  1226.     if (feof(f1)) {
  1227.     error("ferror error 8\n");
  1228.     }
  1229.     if (getc(f1) != EOF) {
  1230.     error("ferror error 9\n");
  1231.     }
  1232.     if (!feof(f1)) {
  1233.     error("ferror error 10\n");
  1234.     }
  1235.     fclose(f1);
  1236.     fd = open("test", O_RDONLY, 0666);
  1237.     if (fd == -1) {
  1238.     error("ferror error 11\n");
  1239.     }
  1240.     f1 = fdopen(fd, "r+");
  1241.     setvbuf(f1, 0, _IONBF, 1);
  1242.     if (putc('x', f1) != EOF) {
  1243.     error("ferror error 12\n");
  1244.     }
  1245.     if (ferror(f1) == 0) {
  1246.     error("ferror error 13\n");
  1247.     }
  1248.     fseek(f1, 0, 0);
  1249.     if (getc(f1) != EOF) {
  1250.     error("ferror error 14\n");
  1251.     }
  1252.     if (ferror(f1) == 0) {
  1253.     error("ferror error 15\n");
  1254.     }
  1255.     clearerr(f1);
  1256.     if (ferror(f1) != 0) {
  1257.     error("ferror error 16\n");
  1258.     }
  1259.     if (getc(f1) != 'a') {
  1260.     error("ferror error 17\n");
  1261.     }
  1262.     fclose(f1);
  1263.  
  1264.     /*
  1265.      * _cleanup
  1266.      */
  1267.  
  1268.     if (fork() == 0) {
  1269.     f1 = fopen("test", "w");
  1270.     if (f1 == NULL) {
  1271.         error("_cleanup error 1\n");
  1272.     }
  1273.     fputs("Test string", f1);
  1274.     exit(0);
  1275.     }
  1276.     wait(&status);
  1277.     if (status.w_T.w_Retcode == 0) {
  1278.     CheckFile("test", "Test string", "_cleanup error 2\n");
  1279.     }
  1280.  
  1281.     /*
  1282.      * fprintf
  1283.      */
  1284.  
  1285.     f1 = fopen("test", "w");
  1286.     f2 = fopen("test", "r");
  1287.     if ((f1 == NULL) || (f2 == NULL)) {
  1288.     error("sprintf error 1\n");
  1289.     }
  1290.     setvbuf(f1, 0, _IOLBF, BUFSIZ);
  1291.     length = fprintf(f1, "%*d %d %d %d\n", 6, 34, 16923, -12, -1);
  1292.     CheckNext(f2, "    34 16923 -12 -1\n", length, "fprintf error 2\n");
  1293.     length = fprintf(f1, "%4d %4d %4d %4d %d %#x %#X\n", 6, 34,
  1294.         16923, -12, -1, 0, 0);
  1295.  
  1296.     CheckNext(f2, "   6   34 16923  -12 -1 0 0\n", length,
  1297.         "fprintf error 3\n");
  1298.  
  1299.     length = fprintf(f1, "%4u %4u %4u %4u %d %#o\n", 6, 34, 16923, -12, -1, 0);
  1300.     CheckNext(f2, "   6   34 16923 4294967284 -1 0\n", length,
  1301.         "fprintf error 4\n");
  1302.  
  1303.     length = fprintf(f1, "%-4d %-4d %-4d %-4ld\n", 6, 34, 16923, -12, -1);
  1304.     CheckNext(f2, "6    34   16923 -12 \n", length,
  1305.         "fprintf error 5\n");
  1306.  
  1307.     length = fprintf(f1, "%04d %04d %04d %04d\n", 6, 34, 16923, -12, -1);
  1308.     CheckNext(f2, "0006 0034 16923 -012\n", length,
  1309.         "fprintf error 6\n");
  1310.  
  1311.     length = fprintf(f1, "%00*d\n", 6, 34, 16923, -12, -1);
  1312.     CheckNext(f2, "000034\n", length, "fprintf error 7\n");
  1313.  
  1314.     length = fprintf(f1, "%4x %4x %4x %4x\n", 6, 34, 16923, -12, -1);
  1315.     CheckNext(f2, "   6   22 421b fffffff4\n", length,
  1316.         "fprintf error 8\n");
  1317.  
  1318.     length = fprintf(f1, "%#x %#X %#X %#x\n", 6, 34, 16923, -12, -1);
  1319.     CheckNext(f2, "0x6 0X22 0X421B 0xfffffff4\n", length,
  1320.         "fprintf error 9\n");
  1321.  
  1322.     length = fprintf(f1, "%#20x %#20x %#20x %#20x\n", 6, 34, 16923, -12, -1);
  1323.     CheckNext(f2, "                 0x6                 0x22               0x421b           0xfffffff4\n", length, "fprintf error 10\n");
  1324.  
  1325.     length = fprintf(f1, "%-#20x %-#20x %-#20x %-#20x\n", 6, 34, 16923, -12, -1);
  1326.     CheckNext(f2, "0x6                  0x22                 0x421b               0xfffffff4          \n", length, "fprintf error 11\n");
  1327.  
  1328.     length = fprintf(f1, "%-#20o %#-20o %#-20o %#-20o\n", 6, 34, 16923, -12, -1);
  1329.     CheckNext(f2, "06                   042                  041033               037777777764        \n", length, "fprintf error 12\n");
  1330.  
  1331.     length = fprintf(f1, "%s %s %c %s\n", "abcd",
  1332.         "This is a very long test string.", 'x', "x");
  1333.     CheckNext(f2, "abcd This is a very long test string. x x\n", length,
  1334.         "fprintf error 13\n");
  1335.  
  1336.     length = fprintf(f1, "%20s %20s %20c %20s\n", "abcd",
  1337.         "This is a very long test string.", 'x', "x");
  1338.     CheckNext(f2, "                abcd This is a very long test string.                    x                    x\n", length, "fprintf error 14\n");
  1339.  
  1340.     length = fprintf(f1, "%.10s %.10s %c %.10s\n", "abcd",
  1341.         "This is a very long test string.", 'x', "x");
  1342.     CheckNext(f2, "abcd This is a  x x\n", length, "fprintf error 15\n");
  1343.  
  1344.     length = fprintf(f1, "%s %s %1 %% %c %s\n", "abcd",
  1345.         "This is a very long test string.", 'x', "x");
  1346.     CheckNext(f2, "abcd This is a very long test string.  % x x\n", length,
  1347.         "fprintf error 16\n");
  1348.  
  1349.     length = fprintf(f1, "%e %e %e %e\n", 34.2e102, 16923.0/247,
  1350.         -.125, -16000., .000053);
  1351.     CheckNext(f2, "3.420000e+103 6.851417e+01 -1.250000e-01 -1.600000e+04\n", length, "fprintf error 17\n");
  1352.  
  1353.     length = fprintf(f1, "%20e %20e %20e %20e\n", 34.2e102, 16923.0/247,
  1354.         -.125, -16000., .000053);
  1355.     CheckNext(f2, "       3.420000e+103         6.851417e+01        -1.250000e-01        -1.600000e+04\n", length, "fprintf error 18\n");
  1356.  
  1357.     length = fprintf(f1, "%.1e %.1e %.1e %.1e\n", 34.2e102, 16923.0/247,
  1358.         -.125, -16000., .000053);
  1359.     CheckNext(f2, "3.4e+103 6.9e+01 -1.3e-01 -1.6e+04\n", length,
  1360.         "fprintf error 19\n");
  1361.  
  1362.     length = fprintf(f1, "%020e %020e %020e %020e\n", 34.2e102, 16923.0/247,
  1363.         -.125, -16000., .000053);
  1364.     CheckNext(f2, "00000003.420000e+103 000000006.851417e+01 -00000001.250000e-01 -00000001.600000e+04\n", length, "fprintf error 20\n");
  1365.  
  1366.     length = fprintf(f1, "%7.1e %7.1e %7.1e %7.1e\n", 34.2e102, 16923.0/247,
  1367.         -.125, -16000., .000053);
  1368.     CheckNext(f2, "3.4e+103 6.9e+01 -1.3e-01 -1.6e+04\n", length,
  1369.         "fprintf error 21\n");
  1370.  
  1371.     length = fprintf(f1, "%f %f %f %f\n", 34.2e102, 16923.0/247,
  1372.         -.125, -16000., .000053);
  1373.     CheckNext(f2, "34200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 68.514170 -0.125000 -16000.000000\n", length, "fprintf error 22\n");
  1374.  
  1375.     length = fprintf(f1, "%.4f %.4f %.4f %.4f %.4f\n", 34.2e102, 16923.0/247,
  1376.         -.125, -16000., .000053);
  1377.     CheckNext(f2, "34200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000 68.5142 -0.1250 -16000.0000 0.0001\n", length, "fprintf error 23\n");
  1378.  
  1379.     length = fprintf(f1, "%.4e %.5e %.6e\n", -9.99995, -9.99995, 9.99995);
  1380.     CheckNext(f2, "-1.0000e+01 -9.99995e+00 9.999950e+00\n", length,
  1381.         "fprintf error 24\n");
  1382.  
  1383.     length = fprintf(f1, "%.4f %.5f %.6f\n", -9.99995, -9.99995, 9.99995);
  1384.     CheckNext(f2, "-10.0000 -9.99995 9.999950\n", length,
  1385.         "fprintf error 25\n");
  1386.  
  1387.     length = fprintf(f1, "%20f %-20f %020f\n", -9.99995, -9.99995, 9.99995);
  1388.     CheckNext(f2, "           -9.999950 -9.999950            0000000000009.999950\n", length, "fprintf error 26\n");
  1389.  
  1390.     length = fprintf(f1, "%-020f %020f\n", -9.99995, -9.99995, 9.99995);
  1391.     CheckNext(f2, "-9.999950            -000000000009.999950\n", length,
  1392.         "fprintf error 27\n");
  1393.  
  1394.     length = fprintf(f1, "%.0e %#.0e\n", -9.99995, -9.99995, 9.99995);
  1395.     CheckNext(f2, "-1e+01 -1.e+01\n", length, "fprintf error 28\n");
  1396.  
  1397.     length = fprintf(f1, "%.0f %#.0f\n", -9.99995, -9.99995, 9.99995);
  1398.     CheckNext(f2, "-10 -10.\n", length, "fprintf error 29\n");
  1399.  
  1400.     length = fprintf(f1, "%.4f %.5f %.6f\n", -9.99995, -9.99995, 9.99995);
  1401.     CheckNext(f2, "-10.0000 -9.99995 9.999950\n", length,
  1402.         "fprintf error 30\n");
  1403.  
  1404.     length = fprintf(f1, "%.3g\n", 12341.0);
  1405.     CheckNext(f2, "1.23e+04\n", length, "fprintf error 31\n");
  1406.  
  1407.     length = fprintf(f1, "%.3G\n", 1234.12345);
  1408.     CheckNext(f2, "1.23E+03\n", length, "fprintf error 32\n");
  1409.  
  1410.     length = fprintf(f1, "%.3g\n", 123.412345);
  1411.     CheckNext(f2, "123\n", length, "fprintf error 33\n");
  1412.  
  1413.     length = fprintf(f1, "%.3g\n", 12.3412345);
  1414.     CheckNext(f2, "12.3\n", length, "fprintf error 34\n");
  1415.  
  1416.     length = fprintf(f1, "%.3g\n", 1.23412345);
  1417.     CheckNext(f2, "1.23\n", length, "fprintf error 35\n");
  1418.  
  1419.     length = fprintf(f1, "%.3g\n", .123412345);
  1420.     CheckNext(f2, "0.123\n", length, "fprintf error 36\n");
  1421.  
  1422.     length = fprintf(f1, "%.3g\n", .012341);
  1423.     CheckNext(f2, "0.0123\n", length, "fprintf error 37\n");
  1424.  
  1425.     length = fprintf(f1, "%.3g\n", .0012341);
  1426.     CheckNext(f2, "0.00123\n", length, "fprintf error 38\n");
  1427.  
  1428.     length = fprintf(f1, "%.3g\n", .00012341);
  1429.     CheckNext(f2, "0.000123\n", length, "fprintf error 39\n");
  1430.  
  1431.     length = fprintf(f1, "%.3g\n", .00001234);
  1432.     CheckNext(f2, "1.23e-05\n", length, "fprintf error 40\n");
  1433.  
  1434.     length = fprintf(f1, "%.4g\n", 9999.5);
  1435.     CheckNext(f2, "1e+04\n", length, "fprintf error 41\n");
  1436.  
  1437.     length = fprintf(f1, "%.4g\n", 999.95);
  1438.     CheckNext(f2, "1000\n", length, "fprintf error 42\n");
  1439.  
  1440.     length = fprintf(f1, "%.3g\n", 1.0);
  1441.     CheckNext(f2, "1\n", length, "fprintf error 43\n");
  1442.  
  1443.     length = fprintf(f1, "%.\n", 1.0);
  1444.     CheckNext(f2, "\n", length, "fprintf error 44\n");
  1445.  
  1446.     length = fprintf(f1, "%.3g\n", .1);
  1447.     CheckNext(f2, "0.1\n", length, "fprintf error 45\n");
  1448.  
  1449.     length = fprintf(f1, "%.3g\n", .01);
  1450.     CheckNext(f2, "0.01\n", length, "fprintf error 46\n");
  1451.  
  1452.     length = fprintf(f1, "%.3g\n", .001);
  1453.     CheckNext(f2, "0.001\n", length, "fprintf error 47\n");
  1454.  
  1455.     length = fprintf(f1, "%.3g\n", .0001);
  1456.     CheckNext(f2, "1e-04\n", length, "fprintf error 48\n");
  1457.  
  1458.     length = fprintf(f1, "%.3g\n", .00001);
  1459.     CheckNext(f2, "1e-05\n", length, "fprintf error 49\n");
  1460.  
  1461.     length = fprintf(f1, "%#.3g\n", 1234.0);
  1462.     CheckNext(f2, "1.23e+03\n", length, "fprintf error 50\n");
  1463.  
  1464.     length = fprintf(f1, "%#.3G\n", 9999.5);
  1465.     CheckNext(f2, "1.00E+04\n", length, "fprintf error 51\n");
  1466.  
  1467.     length = fprintf(f1, "%e %f %g\n", 0.0, 0.0, 0.0, 0.0);
  1468.     CheckNext(f2, "0.000000e+00 0.000000 0\n", length, "fprintf error 52\n");
  1469.  
  1470.     length = fprintf(f1, "%.4e %.4f %.4g\n", 0.0, 0.0, 0.0, 0.0);
  1471.     CheckNext(f2, "0.0000e+00 0.0000 0\n", length, "fprintf error 53\n");
  1472.  
  1473.     length = fprintf(f1, "%#.4e %#.4f %#.4g\n", 0.0, 0.0, 0.0, 0.0);
  1474.     CheckNext(f2, "0.0000e+00 0.0000 0.000\n", length, "fprintf error 54\n");
  1475.  
  1476.     length = fprintf(f1, "%.0e %.0f %.0g\n", 0.0, 0.0, 0.0, 0.0);
  1477.     CheckNext(f2, "0e+00 0 0\n", length, "fprintf error 55\n");
  1478.  
  1479.     length = fprintf(f1, "%#.0e %#.0f %#.0g\n", 0.0, 0.0, 0.0, 0.0);
  1480.     CheckNext(f2, "0.e+00 0. 0.\n", length, "fprintf error 56\n");
  1481.  
  1482.     length = fprintf(f1, "%3.0f %3.0f %3.0f %3.0f\n", 0.0, 0.1, 0.01, 0.001);
  1483.     CheckNext(f2, "  0   0   0   0\n", length, "fprintf error 57\n");
  1484.  
  1485.     length = fprintf(f1, "%3.0f %3.0f %3.0f %3.0f\n", 1.0, 1.1, 1.01, 1.001);
  1486.     CheckNext(f2, "  1   1   1   1\n", length, "fprintf error 58\n");
  1487.  
  1488.     length = fprintf(f1, "%3.1f %3.1f %3.1f %3.1f\n", 0.0, 0.1, 0.01, 0.001);
  1489.     CheckNext(f2, "0.0 0.1 0.0 0.0\n", length, "fprintf error 59\n");
  1490.  
  1491.     fclose(f1);
  1492.     fclose(f2);
  1493.  
  1494.     /*
  1495.      * sscanf
  1496.      */
  1497.  
  1498.     count = sscanf("-20 1476 \n33 0", "%d %d %d %d", &d1, &d2, &d3, &d4);
  1499.     if ((count != 4) || (d1 != -20) || (d2 != 1476) || (d3 != 33)
  1500.         || (d4 != 0)) {
  1501.     error("sscanf error 1\n");
  1502.     }
  1503.  
  1504.     d4 = -1;
  1505.     count = sscanf("-45 16 7890 +10", "%2d %*d %10d %d", &d1, &d2, &d3, &d4);
  1506.     if ((count != 3) || (d1 != -4) || (d2 != 16) || (d3 != 7890)
  1507.         || (d4 != -1)) {
  1508.     error("sscanf error 2\n");
  1509.     }
  1510.  
  1511.     count = sscanf("-45 16 +10 987", "%D %  %hD %d", &d1, &d2, &d3, &d4);
  1512.     if ((count != 4) || (d1 != -45) || (d2 != 16) || (d3 != 10)
  1513.         || (d4 != 987)) {
  1514.     error("sscanf error 3\n");
  1515.     }
  1516.  
  1517.     sa1[0] = sa1[1] = sa1[2] = sa2[0] = sa2[1] = sa2[2] = -1;
  1518.     count = sscanf("14 1ab 62 10", "%hd %x %O %hx", &sa1[1], &d2, &d3,
  1519.         &sa2[1]);
  1520.     if ((count != 4) || (sa1[0] != -1) || (sa1[1] != 14) || (sa1[2] != -1)
  1521.         || (d2 != 427) || (d3 != 50) || (sa2[0] != -1) || (sa2[1] != 0x10)
  1522.         || (sa2[2] != -1)) {
  1523.     error("sscanf error 4\n");
  1524.     }
  1525.  
  1526.     count = sscanf("12345670 1234567890ab cdefg", "%o     %o %x %X",
  1527.         &d1, &d2, &d3, &d4);
  1528.     if ((count != 4) || (d1 != 2739128) || (d2 != 342391) || (d3 != 561323)
  1529.         || (d4 != 52719)) {
  1530.     error("sscanf error 5\n");
  1531.     }
  1532.  
  1533.     count = sscanf("ab123-24642", "%2x %3hx %3o %2ho", &d1, &s1, &d3, &s2);
  1534.     if ((count != 4) || (d1 != 171) || (s1 != 0x123) || (d3 != -20)
  1535.         || (s2 != 0x34)) {
  1536.     error("sscanf error 6\n");
  1537.     }
  1538.  
  1539.     d2 = d3 = d4 = -1;
  1540.     count = sscanf("42 43", "%d %", &d1, &d2, &d3, &d4);
  1541.     if ((count != -1) || (d1 != 42) || (d2 != -1) || (d3 != -1)
  1542.         || (d4 != -1)) {
  1543.     error("sscanf error 7\n");
  1544.     }
  1545.  
  1546.     d2 = d3 = d4 = -1;
  1547.     count = sscanf("42", "%d", &d1, &d2, &d3, &d4);
  1548.     if ((count != 1) || (d1 != 42) || (d2 != -1) || (d3 != -1)
  1549.         || (d4 != -1)) {
  1550.     error("sscanf error 8\n");
  1551.     }
  1552.  
  1553.     d2 = d3 = d4 = -1;
  1554.     count = sscanf("1 2 3 4 5", "%q %r", &d1, &d2, &d3, &d4);
  1555.     if ((count != 2) || (d1 != 1) || (d2 != 2) || (d3 != -1)
  1556.         || (d4 != -1)) {
  1557.     error("sscanf error 9\n");
  1558.     }
  1559.  
  1560.     d3 = d4 = -1;
  1561.     count = sscanf("1234567 234 567  ", "%*3x %x %*o %4o", &d1, &d2, &d3, &d4);
  1562.     if ((count != 2) || (d1 != 17767) || (d2 != 375) || (d3 != -1)
  1563.         || (d4 != -1)) {
  1564.     error("sscanf error 10\n");
  1565.     }
  1566.  
  1567.     d3 = d4 = -1;
  1568.     count = sscanf("1234567 234 567  ", "%*3x %x %*o %4o", &d1, &d2, &d3, &d4);
  1569.     if ((count != 2) || (d1 != 17767) || (d2 != 375) || (d3 != -1)
  1570.         || (d4 != -1)) {
  1571.     error("sscanf error 11\n");
  1572.     }
  1573.  
  1574.     d1 = d2 = d3 = d4 = -1;
  1575.     count = sscanf("a    1234", "%d %d", &d1, &d2, &d3, &d4);
  1576.     if ((count != 0) || (d1 != -1) || (d2 != -1) || (d3 != -1)
  1577.         || (d4 != -1)) {
  1578.     error("sscanf error 11\n");
  1579.     }
  1580.  
  1581.     count = sscanf("12345678", "%2d %2d %2d %2d", &d1, &d2, &d3, &d4);
  1582.     if ((count != 4) || (d1 != 12) || (d2 != 34) || (d3 != 56)
  1583.         || (d4 != 78)) {
  1584.     error("sscanf error 12\n");
  1585.     }
  1586.  
  1587.     d3 = d4 = -1;
  1588.     count = sscanf("1 2 ", "%d %d %d %d", &d1, &d2, &d3, &d4);
  1589.     if ((count != 2) || (d1 != 1) || (d2 != 2) || (d3 != -1)
  1590.         || (d4 != -1)) {
  1591.     error("sscanf error 13\n");
  1592.     }
  1593.  
  1594.     d1 = d2 = d3 = d4 = -1;
  1595.     count = sscanf("  a", " a%d %d %d %d", &d1, &d2, &d3, &d4);
  1596.     if ((count != -1) || (d1 != -1) || (d2 != -1) || (d3 != -1)
  1597.         || (d4 != -1)) {
  1598.     error("sscanf error 14\n");
  1599.     }
  1600.  
  1601.     fp4 = -1.0;
  1602.     count = sscanf("2.1 -3.0e8 .99962 a", "%f%f%f%f", &fp1, &fp2, &fp3, &fp4);
  1603.     CheckFp(count, 3, fp1, fp2, fp3, fp4,
  1604.         "2.100000e+00 -3.000000e+08 9.996200e-01 -1.000000e+00",
  1605.         "sscanf error 15\n");
  1606.  
  1607.     count = sscanf("-1.2345 +8.2 9", "%3e %3f %f %f", &fp1, &fp2, &fp3, &fp4);
  1608.     CheckFp(count, 4, fp1, fp2, fp3, fp4,
  1609.         "-1.000000e+00 2.340000e+02 5.000000e+00 8.200000e+00",
  1610.         "sscanf error 16\n");
  1611.  
  1612.     fp4 = -1.0;
  1613.     count = sscanf("1e00004 332E-4 3e+4", "%f %*2e %f %f", &fp1,
  1614.         &fp2, &fp3, &fp4);
  1615.     CheckFp(count, 3, fp1, fp2, fp3, fp4,
  1616.         "1.000000e+04 2.000000e-04 3.000000e+04 -1.000000e+00",
  1617.         "sscanf error 17\n");
  1618.  
  1619.     fp4 = -1.0;
  1620.     count = sscanf("1. 47.6 2.e2 3.e-", "%f %*f %f %f", &fp1, &fp2,
  1621.         &fp3, &fp4);
  1622.     CheckFp(count, 3, fp1, fp2, fp3, fp4,
  1623.         "1.000000e+00 2.000000e+02 3.000000e+00 -1.000000e+00",
  1624.         "sscanf error 18\n");
  1625.  
  1626.     fp3 = fp4 = -1.0;
  1627.     count = sscanf("1.eabc", "%f %x", &fp1, &fp2, &fp3, &fp4);
  1628.     CheckFp(count, 2, fp1, fp2, fp3, fp4,
  1629.         "1.000000e+00 3.850768e-42 -1.000000e+00 -1.000000e+00",
  1630.         "sscanf error 19\n");
  1631.  
  1632.     count = sscanf("4.6 99999.7 876.43e-1 118", "%f %f %f %e",
  1633.         &fp1, &fp2, &fp3, &fp4);
  1634.     CheckFp(count, 4, fp1, fp2, fp3, fp4,
  1635.         "4.600000e+00 9.999970e+04 8.764300e+01 1.180000e+02",
  1636.         "sscanf error 20\n");
  1637.  
  1638.     count = sscanf("1.2345 697.0e-3 124 .00005", "%F %E %lf %le",
  1639.         &dbl1, &dbl2, &dbl3, &dbl4);
  1640.     CheckFp(count, 4, dbl1, dbl2, dbl3, dbl4,
  1641.         "1.234500e+00 6.970000e-01 1.240000e+02 5.000000e-05",
  1642.         "sscanf error 21\n");
  1643.  
  1644.     count = sscanf("4.6 99999.7 876.43e-1 118", "%F %F %F %F",
  1645.         &dbl1, &dbl2, &dbl3, &dbl4);
  1646.     CheckFp(count, 4, dbl1, dbl2, dbl3, dbl4,
  1647.         "4.600000e+00 9.999970e+04 8.764300e+01 1.180000e+02",
  1648.         "sscanf error 22\n");
  1649.  
  1650.     dbl2 = dbl3 = dbl4 = -1.0;
  1651.     count = sscanf("4.6abc", "%F %F %f %f",
  1652.         &dbl1, &dbl2, &dbl3, &dbl4);
  1653.     CheckFp(count, 1, dbl1, dbl2, dbl3, dbl4,
  1654.         "4.600000e+00 -1.000000e+00 -1.000000e+00 -1.000000e+00",
  1655.         "sscanf error 23\n");
  1656.  
  1657.     dbl3 = dbl4 = -1.0;
  1658.     count = sscanf("4.6 5.2", "%F %F %F %F",
  1659.         &dbl1, &dbl2, &dbl3, &dbl4);
  1660.     CheckFp(count, 2, dbl1, dbl2, dbl3, dbl4,
  1661.         "4.600000e+00 5.200000e+00 -1.000000e+00 -1.000000e+00",
  1662.         "sscanf error 24\n");
  1663.  
  1664.     CheckString("abc defghijk dum ", "%s %3s %20s %s", 4,
  1665.         "abc", "def", "ghijk", "dum",
  1666.         "sscanf error 25\n");
  1667.  
  1668.     CheckString("abc       bcdef", "%5c%c%1s %s", 4,
  1669.         "abc  ", " XXXX", "b", "cdef",
  1670.         "sscanf error 26\n");
  1671.  
  1672.     CheckString("123456 test ", "%*c%*s %s %s %s", 1,
  1673.         "test", "XXXXX", "XXXXX", "XXXXX",
  1674.         "sscanf error 27\n");
  1675.  
  1676.     CheckString("ababcd01234  f 123450", "%4[abcd] %4[abcd] %[^abcdef] %[^0]",
  1677.         4, "abab", "cd", "01234  ", "f 12345",
  1678.         "sscanf error 28\n");
  1679.  
  1680.     CheckString("aaaaaabc aaabcdefg  + +  XYZQR",
  1681.         "%*4[a] %s %*4[a]%s%*4[ +]%10c", 3,
  1682.         "aabc", "bcdefg", "+  XYZQR", "XXXXX",
  1683.         "sscanf error 29\n");
  1684.  
  1685.     /*
  1686.      * printf, scanf, fscanf, sprintf, vprintf, vsprintf
  1687.      */
  1688.  
  1689.     fd = dup(1);
  1690.     fclose(stdout);
  1691.     f1 = fopen("test", "w");
  1692.     count = printf("%d and %d", 47, 102);
  1693.     if (count != 10) {
  1694.     error("printf error 1\n");
  1695.     }
  1696.     count = CheckVprintf("  %x then %x", 15, 65);
  1697.     if (count != 11) {
  1698.     error("printf error 2\n");
  1699.     }
  1700.     fclose(stdout);
  1701.     CheckFile("test", "47 and 102  f then 41", "printf error 3\n");
  1702.     dup2(fd, 1);
  1703.     (void) fdopen(1, "w");
  1704.     close(fd);
  1705.  
  1706.     fd = dup(0);
  1707.     fclose(stdin);
  1708.     f1 = fopen("test", "r");
  1709.     count = scanf("%d and %d %d", &d1, &d2, &d3);
  1710.     if ((count != 2) || (d1 != 47) || (d2 != 102)) {
  1711.     error("scanf error 1\n");
  1712.     }
  1713.     fclose(stdin);
  1714.     dup2(fd, 0);
  1715.     (void) fdopen(0, "r");
  1716.     close(fd);
  1717.  
  1718.     f1 = fopen("test", "r");
  1719.     count = fscanf(f1, "%d and %d %d", &d1, &d2, &d3);
  1720.     if ((count != 2) || (d1 != 47) || (d2 != 102)) {
  1721.     error("fscanf error 1\n");
  1722.     }
  1723.     fclose(f1);
  1724.  
  1725.     if (sprintf(buf, "%s %d", "The value is", 19) != buf) {
  1726.     error("sprintf error 1\n");
  1727.     }
  1728.     if (strcmp(buf, "The value is 19") != 0) {
  1729.     error("sprintf error 2\n");
  1730.     }
  1731.  
  1732.     if (CheckVsprintf(buf, "%s %d", "The value is", 19) != buf) {
  1733.     error("vsprintf error 1\n");
  1734.     }
  1735.     if (strcmp(buf, "The value is 19") != 0) {
  1736.     error("vsprintf error 2\n");
  1737.     }
  1738. }
  1739. @
  1740.  
  1741.  
  1742. 1.12.1.1
  1743. log
  1744. @Initial branch for Sprite server.
  1745. @
  1746. text
  1747. @d20 1
  1748. a20 1
  1749. static char rcsid[] = "$Header: /sprite/src/tests/stdio/RCS/stdio.c,v 1.12 91/12/12 13:43:34 shirriff Exp $ SPRITE (Berkeley)";
  1750. @
  1751.  
  1752.  
  1753. 1.11
  1754. log
  1755. @Fprintf checks 22 and 23 needed to be adjusted again (I don't
  1756. know why floating-poin results keep changing), and Fred made changes
  1757. to match changes to fseek code.
  1758. @
  1759. text
  1760. @d20 1
  1761. a20 1
  1762. static char rcsid[] = "$Header: /sprite/src/tests/stdio/RCS/stdio.c,v 1.10 88/12/15 09:50:57 ouster Exp Locker: douglis $ SPRITE (Berkeley)";
  1763. d30 11
  1764. d44 4
  1765. d201 1
  1766. d490 6
  1767. a495 1
  1768.     CheckFile("test", "a\1\2\3\377\4\5\6\7", "putw error 5\n");
  1769. @
  1770.  
  1771.  
  1772. 1.10
  1773. log
  1774. @Floating-point conversion has changed slightly.  Update test values.
  1775. @
  1776. text
  1777. @d20 1
  1778. a20 1
  1779. static char rcsid[] = "$Header: /t2/test/src/cmds/stdio/RCS/stdio.c,v 1.9 88/10/23 15:39:22 ouster Exp $ SPRITE (Berkeley)";
  1780. d708 80
  1781. d874 1
  1782. a874 1
  1783.     fseek(f2, 0, SEEK_SET);
  1784. d908 1
  1785. a908 1
  1786.     if (ungetc('x', f1) != 0) {
  1787. d911 1
  1788. a911 1
  1789.     if (ungetc('y', f1) != 0) {
  1790. d921 1
  1791. a921 1
  1792.     if (ungetc('#', f1) != 0) {
  1793. d968 4
  1794. a971 1
  1795.     CheckFile("test", "Test output continued again", "fopen error 8\n");
  1796. d1008 4
  1797. a1011 1
  1798.     CheckFile("test", "Again written to\n", "fopen error 19\n");
  1799. d1269 1
  1800. a1269 1
  1801.     CheckNext(f2, "34200000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 68.514170 -0.125000 -16000.000000\n", length, "fprintf error 22\n");
  1802. d1273 1
  1803. a1273 1
  1804.     CheckNext(f2, "34200000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000 68.5142 -0.1250 -16000.0000 0.0001\n", length, "fprintf error 23\n");
  1805. @
  1806.  
  1807.  
  1808. 1.9
  1809. log
  1810. @Change position of "#" in formats, permit flags in any order.
  1811. @
  1812. text
  1813. @d20 1
  1814. a20 1
  1815. static char rcsid[] = "$Header: /t2/test/src/cmds/stdio/RCS/stdio.c,v 1.8 88/10/01 10:17:12 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  1816. d1183 1
  1817. a1183 1
  1818.     CheckNext(f2, "34200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 68.514170 -0.125000 -16000.000000\n", length, "fprintf error 22\n");
  1819. d1187 1
  1820. a1187 1
  1821.     CheckNext(f2, "34200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000 68.5142 -0.1250 -16000.0000 0.0001\n", length, "fprintf error 23\n");
  1822. d1332 1
  1823. a1332 1
  1824.         || (sa2[2] != 0xffff)) {
  1825. @
  1826.  
  1827.  
  1828. 1.8
  1829. log
  1830. @Make sure fdopen seeks to EOF when opened mode "a".
  1831. @
  1832. text
  1833. @d20 1
  1834. a20 1
  1835. static char rcsid[] = "$Header: stdio.c,v 1.7 88/07/21 10:57:09 ouster Exp $ SPRITE (Berkeley)";
  1836. d1132 1
  1837. a1132 1
  1838.     length = fprintf(f1, "%20#x %20#x %20#x %20#x\n", 6, 34, 16923, -12, -1);
  1839. d1135 1
  1840. a1135 1
  1841.     length = fprintf(f1, "%-20#x %-20#x %-20#x %-20#x\n", 6, 34, 16923, -12, -1);
  1842. d1138 1
  1843. a1138 1
  1844.     length = fprintf(f1, "%-20#o %-20#o %-20#o %-20#o\n", 6, 34, 16923, -12, -1);
  1845. d1204 1
  1846. a1204 1
  1847.     length = fprintf(f1, "%.0e %.0#e\n", -9.99995, -9.99995, 9.99995);
  1848. d1207 1
  1849. a1207 1
  1850.     length = fprintf(f1, "%.0f %.0#f\n", -9.99995, -9.99995, 9.99995);
  1851. d1271 1
  1852. a1271 1
  1853.     length = fprintf(f1, "%.3#g\n", 1234.0);
  1854. d1274 1
  1855. a1274 1
  1856.     length = fprintf(f1, "%.3#G\n", 9999.5);
  1857. d1283 1
  1858. a1283 1
  1859.     length = fprintf(f1, "%.4#e %.4#f %.4#g\n", 0.0, 0.0, 0.0, 0.0);
  1860. d1289 1
  1861. a1289 1
  1862.     length = fprintf(f1, "%.0#e %.0#f %.0#g\n", 0.0, 0.0, 0.0, 0.0);
  1863. @
  1864.  
  1865.  
  1866. 1.7
  1867. log
  1868. @Changed return value from putc and fputc.
  1869. @
  1870. text
  1871. @d20 1
  1872. a20 1
  1873. static char rcsid[] = "$Header: stdio.c,v 1.6 88/07/21 09:35:31 ouster Exp $ SPRITE (Berkeley)";
  1874. d972 13
  1875. @
  1876.  
  1877.  
  1878. 1.6
  1879. log
  1880. @Added more tests for fdopen, vprintf, vsprintf.
  1881. @
  1882. text
  1883. @d20 1
  1884. a20 1
  1885. static char rcsid[] = "$Header: stdio.c,v 1.5 88/07/20 18:11:18 ouster Exp $ SPRITE (Berkeley)";
  1886. d343 1
  1887. a343 1
  1888.     if (fputc('c', f1) != 0) {
  1889. d346 1
  1890. a346 1
  1891.     if (fputc('\n', f1) != 0) {
  1892. d357 14
  1893. d373 1
  1894. a373 1
  1895.     error("putc error 9\n");
  1896. d376 1
  1897. a376 1
  1898.     error("putc error 10\n");
  1899. d379 1
  1900. a379 1
  1901.     error("putc error 11\n");
  1902. @
  1903.  
  1904.  
  1905. 1.5
  1906. log
  1907. @Mods for change to fdopen.
  1908. @
  1909. text
  1910. @d20 1
  1911. a20 1
  1912. static char rcsid[] = "$Header: stdio.c,v 1.4 88/06/13 09:59:55 ouster Exp $ SPRITE (Berkeley)";
  1913. d28 1
  1914. d239 62
  1915. d319 1
  1916. a319 1
  1917.     FILE *f1, *f2;
  1918. d924 1
  1919. a924 2
  1920.     fd2 = open("test", O_RDONLY, 0666);
  1921.     if (fd2 == -1) {
  1922. d927 1
  1923. a927 1
  1924.     f1 = fdopen(fd2, "r");
  1925. d934 25
  1926. a965 1
  1927.     close(fd);
  1928. d1469 1
  1929. a1469 1
  1930.      * printf, scanf, fscanf, sprintf
  1931. d1479 4
  1932. d1484 1
  1933. a1484 1
  1934.     CheckFile("test", "47 and 102", "printf error 2\n");
  1935. d1513 7
  1936. @
  1937.  
  1938.  
  1939. 1.4
  1940. log
  1941. @Added getw and putw.  Should be complete now.
  1942. @
  1943. text
  1944. @d20 1
  1945. a20 1
  1946. static char rcsid[] = "$Header: stdio.c,v 1.3 88/06/10 10:19:52 ouster Exp $ SPRITE (Berkeley)";
  1947. d437 1
  1948. a437 1
  1949.     close(1);
  1950. d464 1
  1951. d474 1
  1952. a474 1
  1953.     close(0);
  1954. d504 1
  1955. d1395 2
  1956. a1396 1
  1957.     dup(1, fd);
  1958. d1407 2
  1959. a1408 1
  1960.     dup(0, fd);
  1961. @
  1962.  
  1963.  
  1964. 1.3
  1965. log
  1966. @Intermediate check-in.
  1967. @
  1968. text
  1969. @d20 1
  1970. a20 1
  1971. static char rcsid[] = "$Header: stdio.c,v 1.2 88/06/06 17:46:50 ouster Exp $ SPRITE (Berkeley)";
  1972. d32 1
  1973. a32 1
  1974.  
  1975. d34 14
  1976. a47 2
  1977.  * Utility procedure to make sure that a given file contains a
  1978.  * given value.  Aborts with error if it doesn't.
  1979. d51 1
  1980. a51 1
  1981. checkFile(name, value, errMsg)
  1982. d73 1
  1983. a73 1
  1984.  
  1985. d75 14
  1986. a88 1
  1987.  * Structure for testing fwrite, fread.
  1988. a96 4
  1989. /*
  1990.  * Procedure for comparing two of the above structures.
  1991.  */
  1992.  
  1993. d98 1
  1994. a98 1
  1995. tsCheck(ts1, ts2, msg)
  1996. d113 1
  1997. a113 1
  1998.  
  1999. d115 15
  2000. a129 2
  2001.  * Procedure for testing fprintf:  reads back from a file and
  2002.  * makes sure what was printed had the right length and content.
  2003. d133 1
  2004. a133 1
  2005. checkNext(f, string, length, msg)
  2006. d151 18
  2007. d170 84
  2008. d264 1
  2009. d293 1
  2010. a293 1
  2011.     checkFile("test", "abc\nThis is the second line.\n", "putc error 8\n");
  2012. d376 1
  2013. d379 45
  2014. d464 1
  2015. a464 1
  2016.     checkFile("test", "x more on this line.\nA second line.\n",
  2017. d542 2
  2018. a543 2
  2019.     tsCheck(&tsArray1[0], &tsArray2[0], "fread error 3\n");
  2020.     tsCheck(&tsArray1[1], &tsArray2[1], "fread error 4\n");
  2021. d549 1
  2022. a549 1
  2023.         tsCheck(&tsArray1[i-5], &tsArray2[i], "fread error 6\n");
  2024. d551 1
  2025. a551 1
  2026.         tsCheck(&tsArray1[i+2], &tsArray2[i], "fread error 7\n");
  2027. d557 1
  2028. a557 1
  2029.     tsCheck(&tsArray1[5], &tsArray2[0], "fread error 9\n");
  2030. d561 3
  2031. a563 3
  2032.     tsCheck(&tsArray1[6], &tsArray2[0], "fread error 11\n");
  2033.     tsCheck(&tsArray1[7], &tsArray2[1], "fread error 12\n");
  2034.     tsCheck(&tsArray1[0], &tsArray2[2], "fread error 13\n");
  2035. d597 1
  2036. a597 1
  2037.     checkFile("test", "ab1defg2ijklmnopqrstuvwxy345", "fseek error 6\n");
  2038. d645 1
  2039. a645 1
  2040.     checkFile("test", "", "setvbuf error 4\n");
  2041. d647 1
  2042. a647 1
  2043.     checkFile("test", "abcd\nefghi", "setvbuf error 5\n");
  2044. d657 1
  2045. a657 1
  2046.     checkFile("test", "123456\nghi", "setvbuf error 8\n");
  2047. d661 1
  2048. a661 1
  2049.     checkFile("test", "123456\n7890", "setvbuf error 10\n");
  2050. d663 1
  2051. a663 1
  2052.     checkFile("test", "123456\n7890", "setvbuf error 11\n");
  2053. d667 1
  2054. a667 1
  2055.     checkFile("test", "123456\n7890X", "setvbuf error 12\n");
  2056. d669 1
  2057. a669 1
  2058.     checkFile("test", "123456\n7890XY", "setvbuf error 13\n");
  2059. d674 1
  2060. a674 1
  2061.     checkFile("test", "123456\n7890XYZ", "setvbuf error 15\n");
  2062. d682 1
  2063. a682 1
  2064.     checkFile("test", "123456\n7890XYZ", "setbuf error 2\n");
  2065. d733 1
  2066. a733 1
  2067.     checkFile("test", "", "setbuffer error 3\n");
  2068. d735 1
  2069. a735 1
  2070.     checkFile("test", "ABCDE", "setbuffer error 4\n");
  2071. d738 1
  2072. a738 1
  2073.     checkFile("test", "ABCDEF", "setbuffer error 5\n");
  2074. d783 1
  2075. a783 1
  2076.     checkFile("test", "", "fopen error 2\n");
  2077. d809 1
  2078. a809 1
  2079.     checkFile("test", "Test output continued again", "fopen error 8\n");
  2080. d822 1
  2081. a822 1
  2082.     checkFile("test", "Turd output continued again", "fopen error 12\n");
  2083. d827 1
  2084. a827 1
  2085.     checkFile("test", "", "fopen error 14\n");
  2086. d838 1
  2087. a838 1
  2088.     checkFile("test", "Again written", "fopen error 17\n");
  2089. d846 1
  2090. a846 1
  2091.     checkFile("test", "Again written to\n", "fopen error 19\n");
  2092. d888 1
  2093. a888 1
  2094.     checkFile("test2", "Output data\n", "freopen error 6\n");
  2095. d973 1
  2096. a973 1
  2097.     checkFile("test", "Test string", "_cleanup error 2\n");
  2098. d987 1
  2099. a987 1
  2100.     checkNext(f2, "    34 16923 -12 -1\n", length, "fprintf error 2\n");
  2101. d990 2
  2102. a991 1
  2103.     checkNext(f2, "   6   34 16923  -12 -1 0 0\n", length,
  2104. d993 1
  2105. d995 1
  2106. a995 1
  2107.     checkNext(f2, "   6   34 16923 4294967284 -1 0\n", length,
  2108. d997 1
  2109. d999 1
  2110. a999 1
  2111.     checkNext(f2, "6    34   16923 -12 \n", length,
  2112. d1001 1
  2113. d1003 1
  2114. a1003 1
  2115.     checkNext(f2, "0006 0034 16923 -012\n", length,
  2116. d1005 1
  2117. d1007 2
  2118. a1008 1
  2119.     checkNext(f2, "000034\n", length, "fprintf error 7\n");
  2120. d1010 1
  2121. a1010 1
  2122.     checkNext(f2, "   6   22 421b fffffff4\n", length,
  2123. d1012 1
  2124. d1014 1
  2125. a1014 1
  2126.     checkNext(f2, "0x6 0X22 0X421B 0xfffffff4\n", length,
  2127. d1016 1
  2128. d1018 2
  2129. a1019 1
  2130.     checkNext(f2, "                 0x6                 0x22               0x421b           0xfffffff4\n", length, "fprintf error 10\n");
  2131. d1021 2
  2132. a1022 1
  2133.     checkNext(f2, "0x6                  0x22                 0x421b               0xfffffff4          \n", length, "fprintf error 11\n");
  2134. d1024 2
  2135. a1025 1
  2136.     checkNext(f2, "06                   042                  041033               037777777764        \n", length, "fprintf error 12\n");
  2137. d1028 1
  2138. a1028 1
  2139.     checkNext(f2, "abcd This is a very long test string. x x\n", length,
  2140. d1030 1
  2141. d1033 2
  2142. a1034 1
  2143.     checkNext(f2, "                abcd This is a very long test string.                    x                    x\n", length, "fprintf error 14\n");
  2144. d1037 2
  2145. a1038 1
  2146.     checkNext(f2, "abcd This is a  x x\n", length, "fprintf error 15\n");
  2147. d1041 1
  2148. a1041 1
  2149.     checkNext(f2, "abcd This is a very long test string.  % x x\n", length,
  2150. d1043 1
  2151. d1046 2
  2152. a1047 1
  2153.     checkNext(f2, "3.420000e+103 6.851417e+01 -1.250000e-01 -1.600000e+04\n", length, "fprintf error 17\n");
  2154. d1050 2
  2155. a1051 1
  2156.     checkNext(f2, "       3.420000e+103         6.851417e+01        -1.250000e-01        -1.600000e+04\n", length, "fprintf error 18\n");
  2157. d1054 1
  2158. a1054 1
  2159.     checkNext(f2, "3.4e+103 6.9e+01 -1.3e-01 -1.6e+04\n", length,
  2160. d1056 1
  2161. d1059 2
  2162. a1060 1
  2163.     checkNext(f2, "00000003.420000e+103 000000006.851417e+01 -00000001.250000e-01 -00000001.600000e+04\n", length, "fprintf error 20\n");
  2164. d1063 1
  2165. a1063 1
  2166.     checkNext(f2, "3.4e+103 6.9e+01 -1.3e-01 -1.6e+04\n", length,
  2167. d1065 1
  2168. d1068 2
  2169. a1069 1
  2170.     checkNext(f2, "34200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 68.514170 -0.125000 -16000.000000\n", length, "fprintf error 22\n");
  2171. d1072 2
  2172. a1073 1
  2173.     checkNext(f2, "34200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000 68.5142 -0.1250 -16000.0000 0.0001\n", length, "fprintf error 23\n");
  2174. d1075 1
  2175. a1075 1
  2176.     checkNext(f2, "-1.0000e+01 -9.99995e+00 9.999950e+00\n", length,
  2177. d1077 1
  2178. d1079 1
  2179. a1079 1
  2180.     checkNext(f2, "-10.0000 -9.99995 9.999950\n", length,
  2181. d1081 1
  2182. d1083 2
  2183. a1084 1
  2184.     checkNext(f2, "           -9.999950 -9.999950            0000000000009.999950\n", length, "fprintf error 26\n");
  2185. d1086 1
  2186. a1086 1
  2187.     checkNext(f2, "-9.999950            -000000000009.999950\n", length,
  2188. d1088 1
  2189. d1090 2
  2190. a1091 1
  2191.     checkNext(f2, "-1e+01 -1.e+01\n", length, "fprintf error 28\n");
  2192. d1093 2
  2193. a1094 1
  2194.     checkNext(f2, "-10 -10.\n", length, "fprintf error 29\n");
  2195. d1096 3
  2196. a1098 1
  2197.     checkNext(f2, "-10.0000 -9.99995 9.999950\n", length, "fprintf error 30\n");
  2198. d1100 2
  2199. a1101 1
  2200.     checkNext(f2, "1.23e+04\n", length, "fprintf error 31\n");
  2201. d1103 2
  2202. a1104 1
  2203.     checkNext(f2, "1.23E+03\n", length, "fprintf error 32\n");
  2204. d1106 2
  2205. a1107 1
  2206.     checkNext(f2, "123\n", length, "fprintf error 33\n");
  2207. d1109 2
  2208. a1110 1
  2209.     checkNext(f2, "12.3\n", length, "fprintf error 34\n");
  2210. d1112 2
  2211. a1113 1
  2212.     checkNext(f2, "1.23\n", length, "fprintf error 35\n");
  2213. d1115 2
  2214. a1116 1
  2215.     checkNext(f2, "0.123\n", length, "fprintf error 36\n");
  2216. d1118 2
  2217. a1119 1
  2218.     checkNext(f2, "0.0123\n", length, "fprintf error 37\n");
  2219. d1121 2
  2220. a1122 1
  2221.     checkNext(f2, "0.00123\n", length, "fprintf error 38\n");
  2222. d1124 2
  2223. a1125 1
  2224.     checkNext(f2, "0.000123\n", length, "fprintf error 39\n");
  2225. d1127 2
  2226. a1128 1
  2227.     checkNext(f2, "1.23e-05\n", length, "fprintf error 40\n");
  2228. d1130 2
  2229. a1131 1
  2230.     checkNext(f2, "1e+04\n", length, "fprintf error 41\n");
  2231. d1133 2
  2232. a1134 1
  2233.     checkNext(f2, "1000\n", length, "fprintf error 42\n");
  2234. d1136 2
  2235. a1137 1
  2236.     checkNext(f2, "1\n", length, "fprintf error 43\n");
  2237. d1139 2
  2238. a1140 1
  2239.     checkNext(f2, "\n", length, "fprintf error 44\n");
  2240. d1142 2
  2241. a1143 1
  2242.     checkNext(f2, "0.1\n", length, "fprintf error 45\n");
  2243. d1145 2
  2244. a1146 1
  2245.     checkNext(f2, "0.01\n", length, "fprintf error 46\n");
  2246. d1148 2
  2247. a1149 1
  2248.     checkNext(f2, "0.001\n", length, "fprintf error 47\n");
  2249. d1151 2
  2250. a1152 1
  2251.     checkNext(f2, "1e-04\n", length, "fprintf error 48\n");
  2252. d1154 2
  2253. a1155 1
  2254.     checkNext(f2, "1e-05\n", length, "fprintf error 49\n");
  2255. d1157 2
  2256. a1158 1
  2257.     checkNext(f2, "1.23e+03\n", length, "fprintf error 50\n");
  2258. d1160 1
  2259. a1160 1
  2260.     checkNext(f2, "1.00E+04\n", length, "fprintf error 51\n");
  2261. d1162 27
  2262. d1198 1
  2263. d1205 1
  2264. d1211 7
  2265. a1217 4
  2266.     d1 = d4 = -1;
  2267.     count = sscanf("14 1ab 62 10", "%hd %x %O %hx", &d1, &d2, &d3, &d4);
  2268.     if ((count != 4) || (d1 != 0xeffff) || (d2 != 427) || (d3 != 50)
  2269.         || (d4 != 0x10ffff)) {
  2270. d1220 1
  2271. d1227 4
  2272. a1230 4
  2273.     d2 = d4 = -1;
  2274.     count = sscanf("ab123-24642", "%2x %3hx %3o %2ho", &d1, &d2, &d3, &d4);
  2275.     if ((count != 4) || (d1 != 171) || (d2 != 0x123ffff) || (d3 != -20)
  2276.         || (d4 != 0x34ffff)) {
  2277. d1233 1
  2278. d1240 1
  2279. d1247 1
  2280. d1254 1
  2281. d1261 1
  2282. d1268 1
  2283. d1275 1
  2284. d1281 1
  2285. d1288 1
  2286. d1295 1
  2287. d1298 4
  2288. a1301 4
  2289.     if ((count != 3) || (fp1 != 2.1) || (fp2 != -3.0e8) || (fp3 != .99962)
  2290.         || (fp4 != -1.0)) {
  2291.     error("sscanf error 15\n");
  2292.     }
  2293. d1303 4
  2294. a1306 4
  2295.     if ((count != 4) || (fp1 != -1.0) || (fp2 != 234.0) || (fp3 != 5.0)
  2296.         || (fp4 != 8.2)) {
  2297.     error("sscanf error 16\n");
  2298.     }
  2299. d1310 4
  2300. a1313 4
  2301.     if ((count != 3) || (fp1 != 1.0e4) || (fp2 != 2.0e-04) || (fp3 != 3.0e04)
  2302.         || (fp4 != -1.0)) {
  2303.     error("sscanf error 17\n");
  2304.     }
  2305. d1317 4
  2306. a1320 4
  2307.     if ((count != 3) || (fp1 != 1.0) || (fp2 != 200) || (fp3 != 3.0)
  2308.         || (fp4 != -1.0)) {
  2309.     error("sscanf error 18\n");
  2310.     }
  2311. d1323 96
  2312. a1418 3
  2313.     if ((count != 2) || (fp1 != 1.0) || (fp2 != 3.850768e-42) || (fp3 != -1.0)
  2314.         || (fp4 != -1.0)) {
  2315.     error("sscanf error 19\n");
  2316. @
  2317.  
  2318.  
  2319. 1.2
  2320. log
  2321. @*** empty log message ***
  2322. @
  2323. text
  2324. @d20 1
  2325. a20 1
  2326. static char rcsid[] = "$Header: stdio.c,v 1.1 88/06/06 08:43:33 ouster Exp $ SPRITE (Berkeley)";
  2327. d26 2
  2328. d93 25
  2329. d122 1
  2330. a122 1
  2331.     int i, fd;
  2332. d124 4
  2333. d207 1
  2334. a207 1
  2335.     if (buf[16] != 0377) {
  2336. d230 9
  2337. d387 1
  2338. a387 1
  2339.      * fseek and ftell
  2340. d398 1
  2341. a398 1
  2342.     fseek(f1, 2, 0);
  2343. d403 1
  2344. a403 1
  2345.     fseek(f1, 4, 1);
  2346. d408 1
  2347. a408 1
  2348.     fseek(f1, -1, 2);
  2349. d415 1
  2350. a415 1
  2351.     fseek(f1, 1, 0);
  2352. d422 1
  2353. a422 1
  2354.     fseek(f1, -2, 2);
  2355. d429 16
  2356. d465 1
  2357. a465 1
  2358.     fseek(f1, 0, 0);
  2359. d496 1
  2360. a496 1
  2361.     if ((buf[0] != 0) || (buf[BUFSIZ-2] != ((BUFSIZ-2)&0xff))) {
  2362. d501 1
  2363. a501 1
  2364.     fseek(f2, 14, 0);
  2365. d511 1
  2366. a511 1
  2367.     fseek(f2, BUFSIZ-3, 1);
  2368. d513 1
  2369. a513 1
  2370.     if (c != (BUFSIZ-2)&0xff) {
  2371. d522 1
  2372. a522 1
  2373.     fseek(f1, 0, 0);
  2374. d524 1
  2375. a524 1
  2376.     fseek(f2, 0, 0);
  2377. d532 1
  2378. a532 1
  2379.     fseek(f2, 0, 0);
  2380. d558 493
  2381. @
  2382.  
  2383.  
  2384. 1.1
  2385. log
  2386. @Initial revision
  2387. @
  2388. text
  2389. @d20 1
  2390. a20 1
  2391. static char rcsid[] = "$Header: stdlib.c,v 1.1 88/05/20 16:34:06 ouster Exp $ SPRITE (Berkeley)";
  2392. d42 1
  2393. a42 1
  2394.     char buf[1000];
  2395. d60 31
  2396. d94 1
  2397. a94 1
  2398.     char buf[1000], c;
  2399. d96 1
  2400. d243 259
  2401. @
  2402.